import java.util.Stack;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 31
 * Time: 16:41
 */
//牛客 包含min函数的栈
public class Solution3 {
    //法一 非官方方法
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();
    public void push(int node) {
        if(stack1.isEmpty() && stack2.isEmpty()) {
            stack1.push(node);
            stack2.push(node);
        }else {
            if(node <= stack2.peek()) {
                stack1.push(node);
                stack2.push(node);
            }else {
                stack1.push(node);
            }
        }
    }

    public void pop() {
        int temp = stack1.peek();
        if(temp == stack2.peek()) {
            stack1.pop();
            stack2.pop();
        }else {
            stack1.pop();
        }
    }

    public int top() {
       return stack1.peek();
    }

    public int min() {
       return stack2.peek();
    }
}